package com.eblacorp.archive.dao.fn.oracle;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;

import com.eblacorp.archive.dao.fn.TransactionFileDao;
import com.eblacorp.archive.domain.fn.TransactionFile;
import com.eblacorp.archive.exceptions.NotFnDocumentException;
import com.filenet.api.collection.IndependentObjectSet;
import com.filenet.api.collection.RepositoryRowSet;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;

public class TransactionFileDaoImpl extends GenericFnDaoImpl<TransactionFile> implements TransactionFileDao{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6395042241148611504L;

	@Override
	public List<TransactionFile> getByExampleAndDate(
			TransactionFile transactionFile, Date transactionDateFrom,
			Date transactionDateTo, Integer startPage, Integer pageSize,
			boolean withDocument) throws IllegalArgumentException, NotFnDocumentException, IllegalAccessException, InstantiationException, IntrospectionException, InvocationTargetException {
			List<TransactionFile> objects = null;
		
		SearchSQL searchSQL = getContentEngineUtil().getSeatchSQL(transactionFile, pageSize, new String[]{"TransactionDate"}, new Date[]{transactionDateFrom}, new Date[]{transactionDateTo});
		SearchScope searchScope = new SearchScope(getCeConnectionUtil().getObjectStore());
		if(withDocument){
			IndependentObjectSet independentObjectSet = searchScope.fetchObjects(searchSQL, pageSize, null, null);	
			objects = getContentEngineUtil().getObjects(independentObjectSet);
		}else{
			RepositoryRowSet repositoryRowSet = searchScope.fetchRows(searchSQL, pageSize, null, null);	
			objects = getContentEngineUtil().getObjects(repositoryRowSet);
		}
			
		return objects;
		
	}

}
